package com.sdk.bigdata.model;


import com.alibaba.fastjson.annotation.JSONField;
import com.sdk.bigdata.exceptions.DataException;

import java.util.HashMap;
import java.util.Map;

// 用户行为事件
public class Action extends BaseModel {

    private String event;

    private String uid;

    @JSONField(name = "uid_type")
    private String uidType;

    public Action(){}

    public Action(String type,String event, String uid, String uidType, Map<String, Object> properties) {
        super(type, properties);
        this.event = event;
        this.uid = uid;
        this.uidType = uidType;
    }

    public String getEvent() {
        return event;
    }

    public void setEvent(String event) {
        this.event = event;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getUidType() {
        return uidType;
    }

    public void setUidType(String uidType) {
        this.uidType = uidType;
    }


    @Override
    public void validAttribute() {
        this.setType("action");
        this.setTime(System.currentTimeMillis());
        // check uid
        if (null == this.uid || this.uid.equals("")) {
            throw new DataException("property [uid] can't be empty");
        }
        if (this.uid.length() > 255) {
            throw new DataException("the max length of property [uid] is 255");
        }

        // check model
        if (null == this.event || this.event.equals("")) {
            throw new DataException("model name can't be empty");
        }

        if (null == this.getProperties()) {
            this.setProperties(new HashMap<>());
        }
    }

}
